package poketrade;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import poketrade.entities.PendingOffer;
import poketrade.managers.DealManager;

/**
 * Servlet implementation class DealImageServlet
 */
@WebServlet("/DealImageServlet")
public class DealImageServlet extends BaseHttpServlet {
	private static final long serialVersionUID = 1L;

	@EJB
	private DealManager mgr;
	
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		long id;
		try {
			 id = Long.parseLong(request.getParameter("n"));
		}
		catch (NumberFormatException e)
		{
			response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
			return;
		}
		
		PendingOffer o = mgr.getOffer(id);
		request.setAttribute("n", o.getOffer().getCardIndex());
		forward(request, response, "/ImageBlobServlet");
	}

}
